<template>
	<view>
		<block v-if="loading">
			<empty :loading="true"></empty>
		</block>
		<block v-else>
			<view  class="bt mb10" v-if="role == 2">
				<arrowNav @onClick="chooseType">
					<view class="plr15 ptb10 flex left">
						<text class="pr5 fz16 sIcon-addCircle bold main"></text>
						<view>
							添加点位
						</view>
					</view>
				</arrowNav>
			</view>
			
			<!-- <view class="whiteBg bb">
				<switchTabber :list="statusList" itemKey="title" @change="switchStatus" :index="current"></switchTabber>
			</view> -->
			
			<station :role="role" :list="page.list" @delete="delStation"></station>
			
			<empty :loading="false" :list="page.list"></empty>
			
		</block>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id : '' ,
				stationId : '' ,
				page : {
					list : [] ,
					lastPage : false ,
					pageNumber : 1 ,
					pageSize : 10
				},
				statusList : ["全部"] ,
				current : 0 ,
				loading : true ,
				refresh : false ,
				role : 2
			}
		},
		
		computed:{
			status : function(e){
				if(this.statusList.length == 0){
					return "" ;
				}
				return this.statusList[this.current].value ;
			},
		},
		
		onLoad(p) {
			this.id = p.id ;
			var stationId = p.scene ;
			if (!!stationId && stationId.indexOf("from_") > -1) {
				this.stationId = stationId.replace("from_","");
			}
			this.role = uni.getStorageSync("role");
		},
		
		onShow() {
			this.page.pageNumber = 1 ;
			this.loadData();
		},
		
		onReachBottom() {
			if (this.page.lastPage) {
				return ;
			}
			this.page.pageNumber ++ ;
			this.loadData();
		},
		
		onPullDownRefresh() {
			if (this.refresh) {
				return ;
			}
			uni.startPullDownRefresh({});
			this.refresh = true ;
			this.page.pageNumber = 1 ;
			this.loadData();
		},
		
		methods: {
			
			delStation:function(e){
				this.page.list.splice(e.index,1);
			},
			
			chooseType:function(e){
				uni.showActionSheet({
					itemList:['添加污水类型',"添加废气类型"],
					success: (e) => {
						uni.navigateTo({
							url:`/pages/addStation/addStation${e.tapIndex}?id=${this.id}` ,
							fail: (e) => {
								console.log("e: ",e);
							}
						});
					}
				})
			},
			
			switchStatus:function(e){
				this.current = e.index ;
				this.page.pageNumber = 1 ;
				this.loadData();
			},
			
			loadData:function(e){
				var data = {
					pageNumber : this.page.pageNumber ,
					pageSize : this.page.pageSize ,
					"ts.companyId" : this.id ,
					"ts.id" : this.stationId ,
					"ts.status" : this.status 
				} ;
				this.kit.get("/api/station/list",data,res => {
					if (res.page.pageNumber > 1) {
						res.page.list = this.page.list.concat(res.page.list);
					}else{
						this.statusList = res.stationStatusList ;
					}
					this.page = res.page ;
					this.loading = false ;
					this.refresh = false ;
				});
			},
			
		}
	}
</script>

